#!/bin/sh

ftpServer=58.213.19.139
ftpUserName=joyoung
ftpPassword=suningjoyoungsales
ftpRemoteDir="inventoryreport"
ftpLocalDir="/home/siebel/ftp/local/inventoryreport"
sCurrentDate=$1
logfile=/home/siebel/scripts/ftp_inv.log
downfilesTemp=/home/siebel/transfer_inv.ftp

echo "#-------------  Download Inventory Data at :`date +"%Y-%m-%d %H:%M:%S"`----------#" >> ${logfile}
if [ "${sCurrentDate}" == "" ]
then
        sCurrentDate=$(date +%Y%m%d)
fi

if [ ! -d "${ftpLocalDir}/${sCurrentDate}" ]
then
        mkdir -p "${ftpLocalDir}/${sCurrentDate}"
        echo "Create Dir for ${sCurrentDate}" >> ${logfile}
fi



lftp <<_LABEL
set ftp:passive off
open $ftpServer
user $ftpUserName $ftpPassword
cd $ftpRemoteDir/$sCurrentDate && ls || quit
lcd $ftpLocalDir/$sCurrentDate 
mget *
close 
bye
_LABEL

ls -l $ftpLocalDir/$sCurrentDate | awk p++ | awk '{print $9}' | while read line ;do echo $ftpLocalDir/$sCurrentDate/$line ;done > ${downfilesTemp}
